home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / pcscheme / geneva / sources.exe / SOURCES / ASM / TIMER.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-11-18  |  3.5 KB  |  115 lines

  1. ;* TIMER.ASM
  2. ;************************************************************************
  3. ;*                                    *
  4. ;*        PC Scheme/Geneva 4.00 Borland TASM code            *
  5. ;*                                    *
  6. ;* (c) 1985-1988 by Texas Instruments, Inc. See COPYRIGHT.TXT        *
  7. ;* (c) 1992 by L. Bartholdi & M. Vuilleumier, University of Geneva    *
  8. ;*                                    *
  9. ;*----------------------------------------------------------------------*
  10. ;*                                    *
  11. ;*                Timer & Engine support                *
  12. ;*                                    *
  13. ;*----------------------------------------------------------------------*
  14. ;*                                    *
  15. ;* Created by: John Jensen        Date: 1985            *
  16. ;* Revision history:                            *
  17. ;* - 18 Jun 92:    Renaissance (Borland Compilers, ...)            *
  18. ;*                                    *
  19. ;*                    ``In nomine omnipotentii dei''    *
  20. ;************************************************************************
  21. IDEAL
  22. %PAGESIZE    60, 132
  23. MODEL    medium
  24. LOCALS    @@
  25.  
  26.     INCLUDE    "scheme.ash"
  27.  
  28. GET_VEC    EQU    35h             ;DOS call to retrieve interrupt vector
  29. SET_VEC    EQU    25h             ;DOS call to set vector
  30. TIMER_INT EQU    1ch             ;18.2 Hz timer interrupt number
  31.  
  32. CODESEG
  33.  
  34. tickstat DB    -1             ;0=timeout, 1=engine running,
  35.                     ;-1=no engine running (normal)
  36. clk_ptr    DD    0            ;Former timer vector
  37. time    DD    0             ;Timer ticks
  38.  
  39. ;************************************************************************
  40. ;*     Start timer running                        *
  41. ;*    Calling sequence: set_timer(hi,lo)                *
  42. ;*          Where ---- hi,lo: upper,lower words of initial timer value*
  43. ;*     Returns nonzero iff the set was during normal VM running mode    *
  44. ;************************************************************************
  45. PROC C    settimer USES si di, @@hi:word, @@lo:word
  46.     xor    ax, ax             ;Clear ax
  47.     cmp    [cs:tickstat], -1     ;Check for normal run mode
  48.     jne    @@running
  49.     push    es
  50.     mov    ah, GET_VEC         ;Put present timer interrupt vector
  51.     mov    al, TIMER_INT         ;  into es:bx
  52.     int    MSDOS
  53.     mov    [WORD LOW cs:clk_ptr], bx
  54.     mov    [WORD HIGH cs:clk_ptr], es
  55.     pop    es
  56.     mov    ax, [@@hi]        ;Set timer
  57.     mov    [WORD HIGH cs:time], ax
  58.     mov    ax, [@@lo]
  59.     mov    [WORD LOW cs:time], ax
  60.     push    ds
  61.     mov    ah, SET_VEC         ;Set new interrupt vector
  62.     mov    al, TIMER_INT
  63.     push    cs             ;Put vector segment number in ds
  64.     pop    ds
  65.     lea    dx, [tickhandler]
  66.     int    MSDOS
  67.     pop    ds
  68.     mov    al, 1             ;Denote engine running
  69.     mov    [cs:tickstat], al
  70. @@running:
  71.     ret
  72. ENDP    settimer
  73.  
  74. ;************************************************************************
  75. ;*     Stop the timer                            *
  76. ;*    Calling sequence: rst_timer();                    *
  77. ;*     Returns the number in the counter at the time of reset        *
  78. ;************************************************************************
  79. PROC C    rsttimer USES si di
  80.     cmp    [cs:tickstat], 1    ;Only if timeout or engine running
  81.     ja    @@noreset
  82.     mov    ah, SET_VEC         ;Prepare to reset timer interrupt
  83.     mov    al, TIMER_INT
  84.     push    ds
  85.     lds    dx, [cs:clk_ptr]    ;Put original vector into ds:dx
  86.     int    MSDOS
  87.     pop    ds
  88.     mov    [cs:tickstat], -1     ;Denote normal mode
  89. @@noreset:
  90.     mov    dx, [WORD HIGH cs:time]    ;Return 32-bit clock value
  91.     mov    ax, [WORD LOW cs:time]
  92.     ret
  93. ENDP    rsttimer
  94.  
  95. ;************************************************************************
  96. ;*            The new timer code                *
  97. ;************************************************************************
  98. PROC    tickhandler    far
  99.     sti
  100.     cmp    [cs:tickstat], 0    ;If timeout, do nothing special
  101.     je    @@return
  102.     sub    [WORD LOW cs:time], 1    ;Otherwise decrement counter
  103.     sbb    [WORD HIGH cs:time], 0
  104.     jnz    @@return
  105.     cmp    [WORD LOW cs:time], 0    ;Is the counter down ?
  106.     jnz    @@return
  107.     mov    [cs:tickstat], 0    ;Record timeout event
  108.     call    force_timeout C
  109. @@return:
  110.     jmp    [cs:clk_ptr]        ;Jump to original timer code
  111. ENDP    tickhandler
  112.  
  113.     END
  114.  
  115.